package org.atlantis.evnlib.execution.rejecter;

import java.util.concurrent.BlockingQueue;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 抛弃策略。当任务被拒绝时，抛弃早期未执行的任务。
 * 
 * @author <a href="mailto:seenoevil.cn@gmail.com">李曦</a><br/>
 *         Created at: 2011-7-13 上午10:45:38
 */
public class DiscardRejectedTaskHandler implements RejectedTaskHandler {

	private static final Logger log = LoggerFactory.getLogger(DiscardRejectedTaskHandler.class);

	@Override
	public boolean rejectedTask(String name, Runnable task, BlockingQueue<Runnable> taskQueue) {
		if (log.isDebugEnabled()) log.debug("Discard oldest task for Event<{}>", name);
		taskQueue.poll();
		return taskQueue.offer(task);
	}
}
